<?php

namespace App\Models\Shop;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class WxShopService extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'wx_shop_service';

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {

        });

        static::created(function ($model) {

        });

        static::updating(function ($model) {
            // 在模型更新之前触发的操作
//            $model->original = $model->getOriginal();
        });

        static::updated(function ($model) {
//            $original = $model->original;
//            $changes = $model->getChanges();
//
//            // 对比更新前后的字段
//            foreach ($changes as $key => $value) {
//                if($key == 'status') {
//                    $originalValue = $original[$key];
//
//                }
//            }
        });

        static::deleting(function ($model) {
            // 在删除之前执行的逻辑
            if($model->id <= 5){
                throw new \Exception('不能删除id小于5的系统内置服务');
            }
        });

        static::deleted(function ($model) {

        });
    }

}
